package com.qutan.app.core.domain;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;

/**
 * 动态,附近的人
 * Created by pengweiyuan on 6/20/16.
 */
@Entity
@Table(name = "dynamic")
@DynamicInsert(value = true)
@DynamicUpdate(value = true)
public class Dynamic extends IDEntity {

    @Column(columnDefinition = "bigint comment '动态的ID'")
    private long userId;

    @Column(columnDefinition = "varchar (100) comment '留言者的昵称' ")
    private String userNickName;

    @Column(columnDefinition = "text comment '留言的内容' ")
    private String content;

    @Column(columnDefinition = "varchar (1000) comment '照片路径' ")
    private String images;

    @Column(columnDefinition = "varchar (1000) comment '视频路径' ")
    private String videos;

    @Column(columnDefinition = "varchar (500) comment '位置信息' ")
    private String locations;


    @Column(columnDefinition = "double comment '纬度' ")
    private double latitude;

    @Column(columnDefinition = "double comment '经度 '")
    private double longtitude;


    /**
     * 赞的人ID
     */
    @Column(columnDefinition = "varchar (1000) comment '赞的人ID' ")
    private String appreciates;

    @Transient
    private List<Long>appreciateList=new ArrayList<>();


    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public String getUserNickName() {
        return userNickName;
    }

    public void setUserNickName(String userNickName) {
        this.userNickName = userNickName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getImages() {
        return images;
    }

    public void setImages(String images) {
        this.images = images;
    }

    public String getVideos() {
        return videos;
    }

    public void setVideos(String videos) {
        this.videos = videos;
    }

    public String getLocations() {
        return locations;
    }

    public void setLocations(String locations) {
        this.locations = locations;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongtitude() {
        return longtitude;
    }

    public void setLongtitude(double longtitude) {
        this.longtitude = longtitude;
    }

    public List<Long> getAppreciateList() {
        return appreciateList;
    }

    public void setAppreciateList(List<Long> appreciateList) {
        this.appreciateList = appreciateList;
    }

    public String getAppreciates() {
        if(!this.appreciateList.isEmpty())
            return JSON.toJSONString(this.appreciateList);
        return appreciates;
    }

    public void setAppreciates(String appreciates) {
        this.appreciates = appreciates;
        if(StringUtils.isBlank(appreciates))return;
        this.appreciateList= JSON.parseArray(appreciates,Long.class);
    }

    public Dynamic(){

    }

    public Dynamic( long userId, String userNickName, String content, String images, String videos, String locations, double latitude, double longtitude) {
        this.userId = userId;
        this.userNickName = userNickName;
        this.content = content;
        this.images = images;
        this.videos = videos;
        this.locations = locations;
        this.latitude = latitude;
        this.longtitude = longtitude;
    }
}
